# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :login_utils.py
# @Time      :2022/5/30 0030 19:42
# @Author    :何胜利

# 判断用户是否登录
from flask import g
from functools import wraps


def login_required(func):
    """强制登录"""
    @wraps(func)
    def wrapper(*args, **kwargs):
        # 在视图函数执行前判断是否登录
        print("uid----", g.user_id)
        if g.user_id:
            return func(*args, **kwargs)
        else:
            return {"message": "请先登录"}, 401
    return wrapper


